﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Oracle;

namespace card
{
    public partial class AutoSendCarForm : Form
    {
        private WebDG.Service ws = new card.WebDG.Service();

        public AutoSendCarForm()
        {
            InitializeComponent();
        }

        private void AutoSendCarForm_Load(object sender, EventArgs e)
        {
            ComboBoxBind(cbStackName, "STACKNAME");
            ComboBoxBind(cbGetOwner, "GETOWNER");
            QueryData();
        }

        private void ComboBoxBind(ComboBox ctl, string filedName)
        {
            ctl.Items.Clear();
            string strsq = " SELECT DISTINCT " + filedName + " FROM TRUCK_CARGO_LOGIN order by " + filedName;
            DataTable dt = ws.getDataSet_Serv(strsq).Tables[0];
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    if (!dr.IsNull(0))
                        ctl.Items.Add(dr[0].ToString());
                }
            }
        }

        private void QueryData()
        {
            string strSQL = "select * from TRUCK_AUTO_SENDCAR where 1=1";
            string strStackName = this.cbStackName.Text.Trim();
            string strGetOwner = this.cbGetOwner.Text.Trim();
            if (!string.IsNullOrEmpty(strStackName))
                strSQL += " and stackname like '%" + strStackName + "%'";
            if (!string.IsNullOrEmpty(strGetOwner))
                strSQL += " and getowner like '%" + strGetOwner + "%'";

            this.dgvAutoSendCar.AutoGenerateColumns = false;
            this.dgvAutoSendCar.DataSource = ws.getDataSet_Serv(strSQL).Tables[0];
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            QueryData();
        }
    }
}
